package com.tingyuge.base.structrue.node;

import java.util.List;

/**
 * @Created by xiaodao
 */
public class Solution {

    public static ListNode removeElements(ListNode head, int val) {

        if(head == null){
            return head;
        }else {
            //将删除的节点返回来
           head.next = removeElements(head.next, val);

            return head.val == val? head.next:head;

        }

    }

    public static void main(String[] args) {
        int[]  nums ={1,2,6,3,4,5,6,2};
        ListNode listNode = new ListNode(nums);

        System.out.println(removeElements(listNode,6));
    }

}


class ListNode {
       int val;
     ListNode next;
     ListNode(int x) { val = x; }

     public ListNode(int... value){
         this.val=value[0];

         ListNode cur = this;
         for (int i = 1; i <value.length ; i++) {
               cur.next =  new ListNode(value[i]);
               cur = cur.next;

         }
     }
 }
